package com.qtrue.exer;

/**
 * @Package: com.qtrue.exer
 * @ClassName: BubbleSortTest
 * @Author: xiaoBao
 * @CreateTime: 2022-03-07 9:19
 * @Description:数组冒泡排序的实现
 */
public class BubbleSortTest {
    public static void main(String[] args) {
        int[] arr1 = new int[]{21,51,23,98,-1,34,-12,-15,26,21,72,34,19,42,61,22,61,75};

        // 冒泡排序（数组长度为n，则冒泡n-1轮）
        for(int i=0;i<arr1.length - 1;i++){
            for(int j=0;j < arr1.length - 1 - i;j++){
                if(arr1[j] > arr1[j+1]){
                    int temp = arr1[j];
                    arr1[j] = arr1[j+1];
                    arr1[j+1] = temp;
                }
            }
        }

        for(int i=0;i<arr1.length;i++){
            System.out.print(arr1[i] + "\t");
        }

    }
}
